package com.ruoyi.project.abucoder.detail.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.abucoder.detail.domain.PrizeDetail;
import com.ruoyi.project.abucoder.detail.service.IPrizeDetailService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 抽奖明细Controller
 * 
 * @author wuyy
 * @date 2024-04-28
 */
@Controller
@RequestMapping("/abucoder/detail")
public class PrizeDetailController extends BaseController
{
    private String prefix = "abucoder/detail";

    @Autowired
    private IPrizeDetailService prizeDetailService;

    @RequiresPermissions("abucoder:detail:view")
    @GetMapping()
    public String detail()
    {
        return prefix + "/detail";
    }

    /**
     * 查询抽奖明细列表
     */
    @RequiresPermissions("abucoder:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PrizeDetail prizeDetail)
    {
        startPage();
        List<PrizeDetail> list = prizeDetailService.selectPrizeDetailList(prizeDetail);
        return getDataTable(list);
    }

    /**
     * 导出抽奖明细列表
     */
    @RequiresPermissions("abucoder:detail:export")
    @Log(title = "抽奖明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PrizeDetail prizeDetail)
    {
        List<PrizeDetail> list = prizeDetailService.selectPrizeDetailList(prizeDetail);
        ExcelUtil<PrizeDetail> util = new ExcelUtil<PrizeDetail>(PrizeDetail.class);
        return util.exportExcel(list, "抽奖明细数据");
    }

    /**
     * 新增抽奖明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存抽奖明细
     */
    @RequiresPermissions("abucoder:detail:add")
    @Log(title = "抽奖明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PrizeDetail prizeDetail)
    {
        return toAjax(prizeDetailService.insertPrizeDetail(prizeDetail));
    }

    /**
     * 修改抽奖明细
     */
    @RequiresPermissions("abucoder:detail:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PrizeDetail prizeDetail = prizeDetailService.selectPrizeDetailById(id);
        mmap.put("prizeDetail", prizeDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存抽奖明细
     */
    @RequiresPermissions("abucoder:detail:edit")
    @Log(title = "抽奖明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PrizeDetail prizeDetail)
    {
        return toAjax(prizeDetailService.updatePrizeDetail(prizeDetail));
    }

    /**
     * 删除抽奖明细
     */
    @RequiresPermissions("abucoder:detail:remove")
    @Log(title = "抽奖明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(prizeDetailService.deletePrizeDetailByIds(ids));
    }
}
